*------------------------------------------------------------------------------*
*																			   *
*						Code dependend variable									*
*																			   *
*------------------------------------------------------------------------------*

/* 
Replication Material for:
Maria Preißinger & Harald Schoen (2016): It's not always the campaign - 
Explaining inter-elction switching in Germany, 2009-2013. Electoral Studies.

Date: Sep 2016
*/



*------------------------------------------
* Vote Intention and Final Choice
*------------------------------------------

labelbook V986_A			//old label which we intend to modify
	
lab copy V986_A parties 	//copy old label under new name

lab define parties ///			make desired modifications
 8888 "don't know" ///
 9999 "won't vote" ///
 322 "AfD" ///
 801 "other party", add
 
 labelbook parties 				//anschauen

 
* Vote Intention wave 1 to wave 6 
foreach welle of numlist 1/6 {
	gen a_wabsfull`welle' = a_kp`welle'_190bc
	recode a_wabsfull`welle'  (803 804 993 997 999 1000=.) (998=8888) 
	replace a_wabsfull`welle' = 9999 if a_kp`welle'_170==4 ///
		| a_kp`welle'_170==5 | a_kp`welle'_170==98 
	gen b_wabsfull`welle' = b_kp`welle'_190bb
	recode b_wabsfull`welle' (-99 -97 -95 -93=.) (-98=8888) 
	replace b_wabsfull`welle' = 9999 if b_kp`welle'_170==4 ///
		| b_kp`welle'_170==5 
	lab var a_wabsfull`welle' "Vote Intention"
	lab var b_wabsfull`welle' "Vote Intention"
}

lab val ?_wabsfull? parties

tab1 ?_wabsfull?

tab a_wabsfull1 a_kp1_190bc, m
tab a_wabsfull2 a_kp2_190bc, m
tab a_wabsfull3 a_kp3_190bc, m
tab a_wabsfull4 a_kp4_190bc, m

tab b_wabsfull1 b_kp1_190bb, m
tab b_wabsfull2 b_kp2_190bb, m
tab b_wabsfull3 b_kp3_190bb, m


* Reported vote choice post-election interview wave 7
gen a_wabsfull7 = a_kp7_200bc
recode a_wabsfull7 (803 804 993 997 998 999 1000=.) //"weiß nicht" zählt in Nachwahl zu Missing
replace a_wabsfull7 = 9999 if a_kp7_180==2 | a_kp7_200bc==994 

gen b_wabsfull7 = b_kp7_200bb
recode b_wabsfull7 (-99 -97 -95 -93=.) 
replace b_wabsfull7 = 9999 if b_kp7_180==2 | b_kp7_200bb==-84

lab var a_wabsfull7 "Reported vote"
lab var b_wabsfull7 "Reported vote"
lab val *wabsfull7 parties


tab1 a_wabsfull?
tab1 b_wabsfull?

* Include postal voters
//2009 Problem keine abhängigen Interviews, es zählt erstes interview als Briefwähler
foreach welle of numlist 3/7 {
replace a_wabsfull`welle'= a_kp3_191bc if a_kp3_170==6
}

foreach welle of numlist 4/7 {
replace a_wabsfull`welle' = a_kp4_191bc if a_kp4_170==6 & a_kp3_170~=6
}

foreach welle of numlist 5/7 {
replace a_wabsfull`welle' = a_kp5_191bc if a_kp5_170==6 & a_kp4_170~=6 & a_kp3_170~=6
}

foreach welle of numlist 6/7 {
replace a_wabsfull`welle' = a_kp6_191bc if a_kp6_170==6 & a_kp5_170~=6 & a_kp4_170~=6 & a_kp3_170~=6
}

foreach welle of numlist 3/7 {
recode a_wabsfull`welle' (997 998 999=.)  //Briefwähler dürfen nicht "weiß nicht sagen"
}


tab1 a_wabsfull?

//2013
foreach welle of numlist 3/6 {			
replace b_wabsfull`welle' = b_kp`welle'_191bb if b_kp`welle'_170==6
recode b_wabsfull`welle' (-99 -95 -93=.)
}


replace b_wabsfull7 = b_kp7_191bb if b_kp7_180==6
recode b_wabsfull7 (-99 -95 -93=.)

foreach welle of numlist 4/7 {
replace b_wabsfull`welle' = b_wabsfull3 if b_kp3_170==6
}

foreach welle of numlist 5/7 {
replace b_wabsfull`welle' = b_wabsfull4 if b_kp4_170==6
}

foreach welle of numlist 6/7 {
replace b_wabsfull`welle' = b_wabsfull5 if b_kp5_170==6
}

foreach welle of numlist 7/7 {
replace b_wabsfull`welle' = b_wabsfull6 if b_kp6_170==6
}

tab1 ?_wabsfull?

tab b_wabsfull1 wkp0913, m


* Vote choice dummy for wave 7

foreach year in a {
foreach welle of numlist 7 {
gen `year'_votecdu`welle' = `year'_wabsfull`welle'==1
gen `year'_votespd`welle' = `year'_wabsfull`welle'==4
gen `year'_votefdp`welle' = `year'_wabsfull`welle'==5
gen `year'_votegru`welle' = `year'_wabsfull`welle'==6
gen `year'_votelink`welle' = `year'_wabsfull`welle'==7
gen `year'_voteno`welle' = `year'_wabsfull`welle'==9999
}
}

foreach year in a  {
foreach party in cdu spd fdp gru link no {
foreach welle of numlist 7 {
replace `year'_vote`party'`welle' = . if `year'_wabsfull`welle'==.
}
}
}


*-------------------------------------------
* Recall Vote 09
*--------------------------------------------

gen recallvote = b_kp1_350bb
replace recallvote = 9999 if b_kp1_2780==2 | b_kp1_350bb==-84 //did not vote
replace recallvote = .a if b_kp1_2780==-86 | b_kp1_350bb==-99 ///
	| b_kp1_350bb==-98 | b_kp1_2780==-98  //don't remember

lab val recallvote parties

tab1 recallvote

tab recallvote b_kp1_2790, m 
tab recallvote b_kp1_2780, m


*-------------------------------------------------------
* Inter-election vote switching (Panel)
*-------------------------------------------------------

* Differentiate between all kinds of inter-election-switching patterns
lab define switchlb ///
	1 "2009 und 2013 vote for the same party" ///
	2 "2009 und 2013 vote for different parties" ///
	3 "only 2009 abstention" ///
	4 "only 2013 abstention" ///
	5 "2009 und 2013 abstention"
	
gen switch = 1 if a_wabsfull7==b_wabsfull7 
replace switch = 2 if a_wabsfull7!=b_wabsfull7 
replace switch = 3 if a_wabsfull7==9999 
replace switch = 4 if b_wabsfull7==9999 
replace switch = 5 if a_wabsfull7==9999 & b_wabsfull7==9999 
replace switch = . if a_wabsfull7==. | b_wabsfull7==. 

lab val switch switchlb


* Dummy Inter-election switching
gen wechsler = 0 if switch==1 
replace wechsler = 1 if switch>1 & switch~=.
replace wechsler = . if switch==5
lab var wechsler "Inter-election siwtching"
tab switch wechsler, m

*-----------------------------------------------------
* Between-Campaign Switching (Panel)
*-----------------------------------------------------

* Differentiate between all kinds of between-election-switching patterns

gen earlyswitch = 1 if a_wabsfull7==b_wabsfull1 // gleiche Partei
replace earlyswitch = 2 if a_wabsfull7!=b_wabsfull1 //unterschiedliche Partei
replace earlyswitch = 3 if a_wabsfull7==9999 //2009 nicht gewählt
replace earlyswitch = 4 if b_wabsfull1==9999 | b_wabsfull1==8888 //2013 nicht gewählt/weiß nicht
replace earlyswitch = 5 if a_wabsfull7==9999 & (b_wabsfull1==9999 | b_wabsfull1==8888) //2009 und 2013 nicht gewählt/weiß nicht
replace earlyswitch = . if a_wabsfull7==. | b_wabsfull1==. 


lab val earlyswitch switchlb


* Dummy Between-Camapaign Switching
gen earlywechsler = 0 if earlyswitch==1 
replace earlywechsler = 1 if earlyswitch>1 & earlyswitch~=.
replace earlywechsler = . if a_wabsfull7==9999 & b_wabsfull1==9999
lab var earlywechsler "Between campaign switching"
tab1 earlywechsler


*------------------------------------------
* Inter-Election Switching (Recall)
*--------------------------------------------

* Differentiate between all kinds of patterns
gen recallswitch = 1 if recallvote==b_wabsfull7 // gleiche Partei
replace recallswitch = 2 if recallvote!=b_wabsfull7 //unterschiedliche Partei
replace recallswitch = 3 if recallvote==9999 //2009 nicht gewählt
replace recallswitch = 4 if b_wabsfull7==9999 //2013 nicht gewählt
replace recallswitch = 5 if recallvote==9999 & b_wabsfull7==9999 //2009 und 2013 nicht gewählt
replace recallswitch = .a if recallvote==.a
replace recallswitch = . if recallvote==. | b_wabsfull7==. 

lab val recallswitch switchlb
fre recallswitch switch if switch~=. //mehr Konstanz im Recall
tab recallswitch switch if switch~=., m row 
							//etwa 70% machen den Recall richtig

* Dummy Inter-election switch
gen recallwechsler = 0 if recallswitch==1 
replace recallwechsler = 1 if recallswitch>1 & recallswitch~=.
replace recallwechsler = .a if recallswitch==.a
replace recallwechsler = . if recallswitch==5  //constant notvoters out
tab recallswitch recallwechsler, m


*------------------------------------------
* Between campaign switching (recall)
*------------------------------------------

* Differentiate between all kinds of patterns
gen recallearlyswitch = 1 if recallvote==b_wabsfull1 // gleiche Partei
replace recallearlyswitch = 2 if recallvote!=b_wabsfull1 //unterschiedliche Partei
replace recallearlyswitch = 3 if recallvote==9999 //2009 nicht gewählt
replace recallearlyswitch = 4 if b_wabsfull1==9999 | b_wabsfull1==8888 //2013 nicht gewählt/weiß nicht
replace recallearlyswitch = 5 if recallvote==9999 & (b_wabsfull1==9999 | b_wabsfull1==8888) //2009 und 2013 nicht gewählt/weiß nicht
replace recallearlyswitch = .a if recallvote==.a
replace recallearlyswitch = . if recallvote==. | b_wabsfull1==. 


fre recallearlyswitch

lab var recallearlyswitch "Wechsel zwischen 2009 (Recall!) und 2013"
lab val recallearlyswitch switchi

fre recallearlyswitch

* Dummy 
gen recallearlywechsler = 0 if recallearlyswitch==1 
replace recallearlywechsler = 1 if recallearlyswitch>1 & recallearlyswitch~=.
replace recallearlywechsler = .a if recallearlyswitch==.a
replace recallearlywechsler = . if recallvote==9999 & b_wabsfull1==9999

lab var recallearlywechsler "Between campaign switching Recall"


*-------------------------------------------------------
* Inter-election switching towards a certain party (panel)
*------------------------------------------------------


gen tocdu = 1 if b_wabsfull7==1 & a_wabsfull7~=1 & a_wabsfull7~=.
replace tocdu = 0 if b_wabsfull7>1 & b_wabsfull7~=. & ///
	a_wabsfull7~=1 & a_wabsfull7~=.
fre tocdu

gen tospd = 1 if b_wabsfull7==4 & a_wabsfull7~=4 & a_wabsfull7~=.
replace tospd = 0 if b_wabsfull7~=4 & b_wabsfull7~=. & ///
	a_wabsfull7~=4 & a_wabsfull7~=.
fre tospd

gen tofdp = 1 if b_wabsfull7==5 & a_wabsfull7~=5 & a_wabsfull7~=.
replace tofdp = 0 if b_wabsfull7~=5 & b_wabsfull7~=. & ///
	a_wabsfull7~=5 & a_wabsfull7~=.
	
gen togru = 1 if b_wabsfull7==6 & a_wabsfull7~=6 & a_wabsfull7~=.
replace togru = 0 if b_wabsfull7~=6 & b_wabsfull7~=. & ///
	a_wabsfull7~=6 & a_wabsfull7~=.
	
gen tolink = 1 if b_wabsfull7==7 & a_wabsfull7~=7 & a_wabsfull7~=.
replace tolink = 0 if b_wabsfull7~=7 & b_wabsfull7~=. & ///
	a_wabsfull7~=7 & a_wabsfull7~=.

lab var tocdu "change towards CDU/CSU"
lab var tospd "change towards SPD"
lab var tofdp "change towards FDP"
lab var togru "change towards Greens"
lab var tolink "change towards Left"


*-----------------------------------------------
* Campaign Switching without replacing missings
*-----------------------------------------------								

/* Only for cases who participated in all waves. But: 
In 2009 additional respondents were invited to join the
panel in wave 2. When measuring stability of
vote intentions of these people over the course of the campaign 
we have to start at wave 2, not wave 1*/


* 2009
egen a_help1 = diff(a_wabsfull?) if a_w1==1  //respondents starting the panel in wave 1
replace a_help1 = . if a_w1==1 & (a_wabsfull1==. | a_wabsfull2==. ///
	  | a_wabsfull3==. | a_wabsfull4==. | a_wabsfull5==. | ///
	  a_wabsfull6==. | a_wabsfull7==.)
egen a_help2 = diff(a_wabsfull2 a_wabsfull3 a_wabsfull4 /// respondents starting the panel in wave 2
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_w1==0  
replace a_help2 = . if a_w1==0 & (a_wabsfull2==. ///
	  | a_wabsfull3==. | a_wabsfull4==. | a_wabsfull5==. | ///
	  a_wabsfull6==. | a_wabsfull7==.)
	  
gen a_kampwechs = a_help1 if a_w1==1
replace a_kampwechs = a_help2 if a_w1==0
drop a_help?	 	  
	  
lab var a_kampwechs "Campaign switch 2009"
lab define kampwechs ///
	0 "in all waves same party" ///
	1 "at least one switch"
lab val a_kampwechs kampwechs


* 2013
egen b_kampwechs = diff(b_wabsfull?)
replace b_kampwechs = . if b_wabsfull1==.  | b_wabsfull2==. ///
	  | b_wabsfull3==. | b_wabsfull4==. | b_wabsfull5==. | b_wabsfull6==. ///
	  | b_wabsfull7==.	
replace b_kampwechs = . if b_wabsfull1==801 & b_wabsfull1==801 /// vote intention for undefined "other parties"
	  & b_wabsfull2==801 & b_wabsfull3==801 & b_wabsfull4==801 ///
	  & b_wabsfull5==801 & b_wabsfull6==801 & b_wabsfull7==801
lab var b_kampwechs "Campaign switch 2013"
lab val b_kampwechs kampwechs
	  
tab1 b_kampwechs


*------------------------------------------------------------------------
* Campaign Switching with replacing missing values
*------------------------------------------------------------------------

/* Problem: Missings in single waves reduces sample size
in ?_kampwechs. 

Cosider the following sequence of vote intentions of an individual:
(CDU) (CDU) (FDP) (interview missing) (CDU) (CDU) (CDU) 
We know that this person is campaign switcher irrespective of her
true vote intention in the missing wave because she has switched before. 
We have to make no assumptions about the missing value.

Consider the following sequence:
(SPD) (SPD) (SPD) (interview missing) (SPD) (SPD) (SPD)
Here we have to make an assumption about the missing
vote intention. If only one single wave is missing,
in this analysis we assume stability.

If more than one wave is missing we set the campaign switch variable to missing.

In the following code, stability of vote intention is measured with the diff-function
if vote intention is missing for only one wave: wave 1, wave2, wave3, wave4, wave5, wave6
(again wave 2-starters are treated separately)
*/


* 2009: Regular participants
* Wave 1 missing
egen a_kampwe_o1 = diff(a_wabsfull2 a_wabsfull3 a_wabsfull4 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull1==. & ///
	!missing(a_wabsfull2, a_wabsfull3, a_wabsfull4, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7)

* Wave 2 missing
egen a_kampwe_o2 = diff(a_wabsfull1 a_wabsfull3 a_wabsfull4 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull2==. & ///
	!missing(a_wabsfull1, a_wabsfull3, a_wabsfull4, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7)
	
* wave 3 missing
egen a_kampwe_o3 = diff(a_wabsfull1 a_wabsfull2 a_wabsfull4 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull3==. & ///
	!missing(a_wabsfull1, a_wabsfull2, a_wabsfull4, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7)
	
* wave 4 is missing
egen a_kampwe_o4 = diff(a_wabsfull1 a_wabsfull2 a_wabsfull3 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull4==. & ///
	!missing(a_wabsfull1, a_wabsfull2, a_wabsfull3, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7)
	
* wave 5 is missing
egen a_kampwe_o5 = diff(a_wabsfull1 a_wabsfull2 a_wabsfull3 ///
	a_wabsfull4 a_wabsfull6 a_wabsfull7) if a_wabsfull5==. & ///
	!missing(a_wabsfull1, a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull6, a_wabsfull7)
	
* wave 6 is missing
egen a_kampwe_o6 = diff(a_wabsfull1 a_wabsfull2 a_wabsfull3 ///
	a_wabsfull4 a_wabsfull5 a_wabsfull7) if a_wabsfull6==. & ///
	!missing(a_wabsfull1, a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull7)
	
* 2009: wave 2- starters
* wave 3 is missing
egen a_kampwe_o3n = diff(a_wabsfull2 a_wabsfull4 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull3==. & ///
	!missing(a_wabsfull2, a_wabsfull4, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7) & a_w1==0
* wave 4 is missing
egen a_kampwe_o4n = diff(a_wabsfull2 a_wabsfull3 ///
	a_wabsfull5 a_wabsfull6 a_wabsfull7) if a_wabsfull4==. & ///
	!missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull5, a_wabsfull6, a_wabsfull7) & a_w1==0
* wave 5 is missing
egen a_kampwe_o5n = diff(a_wabsfull2 a_wabsfull3 ///
	a_wabsfull4 a_wabsfull6 a_wabsfull7) if a_wabsfull5==. & ///
	!missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull6, a_wabsfull7) & a_w1==0
* wave 6 is missing
egen a_kampwe_o6n = diff(a_wabsfull2 a_wabsfull3 ///
	a_wabsfull4 a_wabsfull5 a_wabsfull7) if a_wabsfull6==. & ///
	!missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull7) & a_w1==0

	
* 2013
* wave 1 is missing
	egen b_kampwe_o1 = diff(b_wabsfull2 b_wabsfull3 b_wabsfull4 ///
	b_wabsfull5 b_wabsfull6 b_wabsfull7) if b_wabsfull1==. & ///
	!missing(b_wabsfull2, b_wabsfull3, b_wabsfull4, ///
	b_wabsfull5, b_wabsfull6, b_wabsfull7)
* wave 2 is missing
	egen b_kampwe_o2 = diff(b_wabsfull1 b_wabsfull3 b_wabsfull4 ///
	b_wabsfull5 b_wabsfull6 b_wabsfull7) if b_wabsfull2==. & ///
	!missing(b_wabsfull1, b_wabsfull3, b_wabsfull4, ///
	b_wabsfull5, b_wabsfull6, b_wabsfull7)
* wave 3 is missing
egen b_kampwe_o3 = diff(b_wabsfull1 b_wabsfull2 b_wabsfull4 ///
	b_wabsfull5 b_wabsfull6 b_wabsfull7) if b_wabsfull3==. & ///
	!missing(b_wabsfull1, b_wabsfull2, b_wabsfull4, ///
	b_wabsfull5, b_wabsfull6, b_wabsfull7)
* wave 4 is missing
egen b_kampwe_o4 = diff(b_wabsfull1 b_wabsfull2 b_wabsfull3 ///
	b_wabsfull5 b_wabsfull6 b_wabsfull7) if b_wabsfull4==. & ///
	!missing(b_wabsfull1, b_wabsfull2, b_wabsfull3, ///
	b_wabsfull5, b_wabsfull6, b_wabsfull7)
* wave 5 is missing
egen b_kampwe_o5 = diff(b_wabsfull1 b_wabsfull2 b_wabsfull3 ///
	b_wabsfull4  b_wabsfull6 b_wabsfull7) if b_wabsfull5==. & ///
	!missing(b_wabsfull1, b_wabsfull2, b_wabsfull3, ///
	b_wabsfull4, b_wabsfull6, b_wabsfull7)
* wave 6 is missing
egen b_kampwe_o6 = diff(b_wabsfull1 b_wabsfull2 b_wabsfull3 ///
	b_wabsfull4 b_wabsfull5 b_wabsfull7) if b_wabsfull6==. & ///
	!missing(b_wabsfull1, b_wabsfull2, b_wabsfull3, ///
	b_wabsfull4, b_wabsfull5, b_wabsfull7)
	
	
* Target variable	
foreach year in a b {
gen `year'_kampwechs_nb = `year'_kampwechs
lab var `year'_kampwechs_nb "campaign switching replacing missings"

foreach num of numlist 1/6 {
replace `year'_kampwechs_nb = `year'_kampwe_o`num' ///
	if `year'_kampwe_o`num'~=.
}
}

foreach num of numlist 3/6 {
replace a_kampwechs_nb = a_kampwe_o`num'n==1 if a_kampwe_o`num'n~=.
}

	
sum ?_kampwechs*		//very similar aggregate shares


	
*-------------------------------------------------------------
* Campaign Switching: Set all stable non-voters to mssing 
*-------------------------------------------------------------

/* If someone intends to abstain from voting during the whole
campaign the variable is replaced to missing */


* campaign switching variable based on respondnets without
* missing waves
replace a_kampwechs = . if a_wabsfull1==9999 & ///
	a_wabsfull2==9999 & a_wabsfull3==9999 & ///
	a_wabsfull4==9999 & a_wabsfull5==9999 & ///
	a_wabsfull6==9999 & a_wabsfull7==9999
replace a_kampwechs = . if a_w1==0 & ///
	a_wabsfull2==9999 & a_wabsfull3==9999 & ///
	a_wabsfull4==9999 & a_wabsfull5==9999 & ///
	a_wabsfull6==9999 & a_wabsfull7==9999
	
replace b_kampwechs = . if b_wabsfull1==9999 & ///
	b_wabsfull2==9999 & b_wabsfull3==9999 & ///
	b_wabsfull4==9999 & b_wabsfull5==9999 & ///
	b_wabsfull6==9999 & b_wabsfull7==9999	
	
	
* campaign switching variable based on respondents with
* one missing wave as well

/* Solution: Count how often wabsfull is equal to missing +
summ up all values of wabsfull. If a respondent has two missing
values and in all non-missing waves intends to abstain his
row total of wabsfull equals (7-2)*9999=49995*/


foreach year in a b {	
egen `year'_wabsmis = rowmiss(`year'_wabsfull?)
egen `year'_wabstotal = rowtotal(`year'_wabsfull?), missing
}


foreach year in a b {
foreach num of numlist 0/6 {
replace `year'_kampwechs_nb = . if `year'_wabsmis==`num' ///
	& `year'_wabstotal==((7-`num')*9999)
}
}


drop *wabsmis *wabstotal


*--------------------------------------------------
* Patterns of Electoral Decision Making 
*-----------------------------------------------------

/* "don't know" and "won't vote" in wave 1 in 2013 are both considered 
as being undecided. All cases that reported to have abstained from
voting either in 2009 or 2013 are part of the residual category "99 combinations 
with non-voting - meaning they are not party of categories 1-8
 */


lab define pattern_voters ///
	1 "stable party voter" ///
	3 "between campaign conversion" ///
	4 "campaign activation of previously unsure" ///
	5 "campaign conversion of previously unsure" ///
	6 "between campaign conversion and campaign conversion" ///
	7 "between campaign conversion and campaign reconversion" ///
	8 "campaign conversion of previously decided" ///
	99 "combinations with non-voting", replace

gen pattern_voters = 1 if wechsler==0 & earlywechsler==0 
replace pattern_voters = 3 if wechsler==1 & earlywechsler==1 ///
	& b_wabsfull1==b_wabsfull7
replace pattern_voters = 4 if (b_wabsfull1==8888 | b_wabsfull1==9999) & ///
	wechsler==0 & earlywechsler==1
replace pattern_voters = 5 if (b_wabsfull1==8888 | b_wabsfull1==9999) & ///
	wechsler==1 & earlywechsler==1 ///
	& b_wabsfull1~=b_wabsfull7
replace pattern_voters = 6 if wechsler==1 & ///
	earlywechsler==1 & b_wabsfull1~=b_wabsfull7 & pattern_voters~=5
replace pattern_voters = 7 if wechsler==0 & ///
	earlywechsler==1 & pattern_voters~=4
replace pattern_voters = 8 if earlywechsler==0 & wechsler==1
replace pattern_voters = 99 if a_wabsfull7==9999 | b_wabsfull7==9999
replace pattern_voters = . if a_wabsfull7==. | b_wabsfull1==. | ///
	b_wabsfull7==.

lab val pattern_voters pattern_voters


*-------------------------------------------------------------------------------
* Patterns of Electoral Decision Making using Recall Measure of Vote Choice 09
*-------------------------------------------------------------------------------

lab define pattern_votersrecall ///
	1 "stable party voter" ///
	3 "between campaign conversion" ///
	4 "campaign activation of previously unsure" ///
	5 "campaign conversion of previously unsure" ///
	6 "between campaign conversion and campaign conversion" ///
	7 "between campaign conversion and campaign reconversion" ///
	8 "campaign conversion of previously decided" ///
	9 "stable party voter (no information from recall)" ///	
	10 "campaign activation from unsure (no information from recall)" ///	
	11 "campaign conversion (no information from recall)" ///
	99 "residual: combinations with non-voting", replace

	
gen recallpattern_voters = 1 if recallwechsler==0 & recallearlywechsler==0 
replace recallpattern_voters = 3 if recallwechsler==1 & recallearlywechsler==1 ///
	& b_wabsfull1==b_wabsfull7
replace recallpattern_voters = 4 if recallwechsler==0 & recallearlywechsler == 1 & ///
	(b_wabsfull1==8888 | b_wabsfull1==9999)
replace recallpattern_voters = 5 if (b_wabsfull1==8888 | b_wabsfull1==9999) & ///
	recallwechsler==1 & recallearlywechsler==1 ///
	& b_wabsfull1~=b_wabsfull7
replace recallpattern_voters = 6 if recallwechsler==1 & ///
	recallearlywechsler==1 & b_wabsfull1~=b_wabsfull7 & recallpattern_voters~=5
replace recallpattern_voters = 7 if recallwechsler==0 & ///
	recallearlywechsler==1 & recallpattern_voters~=4
replace recallpattern_voters = 8 if recallearlywechsler==0 & recallwechsler==1
replace recallpattern_voters = 9 if recallvote==.a & ///
	b_wabsfull1==b_wabsfull7 & b_wabsfull7~=. & b_wabsfull7~=9999
replace recallpattern_voters = 10 if recallvote==.a & ///
	(b_wabsfull1==8888 | b_wabsfull1==9999) & ///
	b_wabsfull7<9999
replace recallpattern_voters = 11 if recallvote==.a & ///
	b_wabsfull1~=b_wabsfull7 & b_wabsfull1<8888 & b_wabsfull7<8888
replace recallpattern_voters = 99 if recallvote==9999 | b_wabsfull7==9999
replace recallpattern_voters = . if recallvote==. | b_wabsfull1==. | b_wabsfull7==.	
	
lab val recallpattern_voters pattern_votersrecall

tab recallpattern_voters recallwechsler, m


	

